Repository navigation
fix(remote): send again a tab close the paired host never received - #29468
Conversation
Closing a paired host's tab prunes the local mirror at once and asks the host to close it. When the connection dropped mid-close the renderer cleared its close intent, so the host's next snapshot after reconnect brought the tab back. A user close that fails without reaching the host is now held: the tab stays hidden, and the close is sent again when a snapshot proves the host is reachable and still lists it, up to three times before the tab is shown.
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🔵 Low · up to
|
…pairing Codex review: an unchanged reconnect snapshot is filtered before apply, so the replay now fires when any snapshot is received; a replay is refused once the environment is re-paired; replays survive a subscription reinstall and re-assert their hide; giving up re-accepts the current snapshot so the tab actually returns.
… unhide evicted ones Codex review: an unpublished or retired-epoch frame could drop a pending replay, and an evicted replay kept its tab hidden with nothing left to send.
…hide in-flight ones Codex review: a real-epoch snapshot can omit tabs it is unsure of, so absence no longer drops a held close; and a snapshot listing a tab whose close is in flight re-asserts its hide after a subscription reinstall.
Codex review: subscriptions are change-driven, so an idle worktree might never publish the snapshot that makes the next attempt due.
Codex review: an idle host may publish nothing after a held close, so the first replay also needs a scheduled re-list.
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
a0933787-ef38-4eaf-a5fe-92f0d47ca4f8
📒 Files selected for processing: 5
src/renderer/src/runtime/web-runtime-session-tab-activate-close.test.tssrc/renderer/src/runtime/web-runtime-session-tab-lifecycle.tssrc/renderer/src/runtime/web-session-close-replay.test.tssrc/renderer/src/runtime/web-session-close-replay.tssrc/renderer/src/runtime/web-session-tabs-sync/tracking.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
| ? { expectedPairingRevision: replay.owner.pairingRevision } | ||
| : {}) | ||
| }) | ||
| const settled = settleWebSessionCloseReplay(replay, outcome !== 'failed') |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Treat a definitive refusal of a replayed close as settled, not as a retry.
closeWebRuntimeSessionTab returns 'failed' for two different cases:
- The close did not reach the host (undelivered).
- The host refused the close with a structured
RuntimeRpcCallErrorcode that is not inUNDELIVERED_CLOSE_CODES.
On a refusal, the inner catch takes the else branch at Line 324-331 and clears the close intents. The tab becomes visible again. Line 150 still passes delivered = false, so the replay stays in pendingReplays as 'retry'. The next snapshot that lists the tab then runs replayWebSessionClosesDueForSnapshot. That call hides the tab again and sends the close again. The tab flickers and the close is resent until the attempt limit is reached.
The comment at Line 93-94 says a structured refusal "is an answer." The replay path does not follow that contract.
The fix: return a distinct outcome for undelivered failures, or have the replay classify the error. Settle as delivered when the failure is a definitive refusal.
Proposed direction
-export type WebRuntimeSessionTabCloseOutcome = 'applied' | 'unknown-tab' | 'failed'
+export type WebRuntimeSessionTabCloseOutcome = 'applied' | 'unknown-tab' | 'failed' | 'undelivered'
...
- return hostHasNoSuchTab ? 'unknown-tab' : 'failed'
+ if (hostHasNoSuchTab) return 'unknown-tab'
+ return isUndeliveredCloseFailure(error) ? 'undelivered' : 'failed'
...
- const settled = settleWebSessionCloseReplay(replay, outcome !== 'failed')
+ const settled = settleWebSessionCloseReplay(replay, outcome !== 'undelivered')If you add a new outcome value, check the existing callers that compare against 'failed'.
| )) { | ||
| for (const hostTabId of replay.hostTabIds) { | ||
| recordWebSessionCloseIntent(replay.owner, replay.worktreeId, hostTabId, Date.now()) | ||
| makeWebSessionCloseIntentDurable(replay.owner, replay.worktreeId, hostTabId) | ||
| } | ||
| } | ||
| const due = takeDueWebSessionCloseReplays(owner, snapshot.worktree, presentHostTabIds) | ||
| if (due.length === 0) { | ||
| return | ||
| } | ||
| // Lazy: the lifecycle module reaches the store, which loads this module. | ||
| void import('./web-runtime-session-tab-lifecycle').then(({ replayWebSessionTabCloses }) => | ||
| replayWebSessionTabCloses(environmentId, due) | ||
| ) | ||
| } |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '75,158p' src/renderer/src/runtime/web-session-close-replay.ts
sed -n '105,128p' src/renderer/src/runtime/web-session-tabs-sync/tracking.tsRepository: stablyai/orca
Length of output: 4385
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- replay helper imports and callers ---'
rg -n -F --glob '*.ts' -e 'replayWebSessionTabCloses' -e 'replayWebSessionClosesDueForSnapshot' -e 'settleWebSessionCloseReplay' src/renderer/src
printf '%s\n' '--- lifecycle implementation ---'
rg -n -F --glob '*.ts' -- 'async function replayWebSessionTabCloses' 'function replayWebSessionTabCloses' 'export const replayWebSessionTabCloses' src/renderer/src
sed -n '1,260p' src/renderer/src/runtime/web-runtime-session-tab-lifecycle.ts
printf '%s\n' '--- replay module complete relevant range ---'
sed -n '1,180p' src/renderer/src/runtime/web-session-close-replay.tsRepository: stablyai/orca
Length of output: 19772
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- close call error path ---'
sed -n '220,430p' src/renderer/src/runtime/web-runtime-session-tab-lifecycle.ts
printf '%s\n' '--- replay tests ---'
sed -n '1,190p' src/renderer/src/runtime/web-session-close-replay.test.ts
sed -n '600,750p' src/renderer/src/runtime/web-runtime-session-tab-activate-close.test.tsRepository: stablyai/orca
Length of output: 16905
Handle lazy replay import failures.
When an authoritative snapshot lists a held tab, takeDueWebSessionCloseReplays marks the replay in flight before the lazy import runs. If that import rejects, no settlement runs. Later snapshots skip the replay because it remains in flight, while its close intent keeps the tab hidden. Add a rejection path that resets the replay and applies the same retry or give-up cleanup as the normal dispatch path.
ELI5
If you close a tab that belongs to a paired Orca server while the connection drops, the close never reaches the server. When you reconnect, the server still has the tab, so it comes back. Now Orca remembers the close and sends it again once the server is reachable, so a tab you closed stays closed.
What Changed
Before: closing a host-owned tab (paired server, or the paired web client) did three things. It removed the local copy at once, recorded a short-lived "closing" marker, and sent
session.tabs.close. If that call failed because the connection dropped or timed out (anything except a definitivetab_not_found), the marker was cleared and the close was forgotten. The host's first snapshot after reconnect re-added the tab. This is the third cause in STA-6224. The other two (fix(runtime): a terminal close commits in the session partition that holds the tab #27119 and fix(terminal): closing a tab is never a silent no-op #27132) are already on main.After: a user close that fails without reaching the host now does two things:
The replay is pinned to the pairing it was made under, so a re-paired host never receives it. After three undelivered sends (or if the bounded queue evicts the entry) the tab is shown again, so a host that keeps failing can't hide a live tab forever.
Mechanism:
src/renderer/src/runtime/web-session-close-replay.tsholds the replays.web-runtime-session-tab-lifecycle.tsholds the close on an undelivered failure (a bare rejection, orruntime_unavailable/remote_runtime_unavailable/runtime_timeout/remote_runtime_timeout). It also exportsreplayWebSessionTabCloses.web-session-tabs-sync/tracking.ts(recordReceivedWebSessionTabsSnapshot) makes replays due, after the existing retired-epoch and unpublished-snapshot guards. It also re-asserts the hide, because a subscription reinstall clears close intents.Why
The execution host owns the tab, so the close has to reach it. Hiding the tab locally isn't enough. I considered three other approaches:
A snapshot is the one signal that proves both "reachable" and "still holds it". Lifecycle closes (cleanup or process exit) and structured refusals, such as a pairing conflict, keep the current clear-on-failure behavior, because those aren't the user's explicit intent or are a definitive answer.
Wire compatibility: nothing new on the wire. It resends the same
session.tabs.closewithreason: 'user', which every host already accepts. A second close of a tab the host already removed answerstab_not_found, which is already handled as "gone".Limitation: replays live in memory, so a close made just before quitting the app while disconnected is still lost. Making it durable across restarts would mean persisting to main, which is a larger change.
Linked Issue
Linear STA-6224 (third cause). Related to #17767. I'm not closing that GitHub issue from here.
Visual Proof
N/A — this changes when an already-sent close is sent again after a reconnect. The tab bar looks the same; the closed tab just stays closed.
Testing
src/renderer/src/runtime/web-runtime-session-tab-activate-close.test.ts:session.tabs.closeagain and settles.src/renderer/src/runtime/web-session-close-replay.test.ts:origin/main.The lifecycle tests also cover the scheduled re-list after holding a close and after a failed replay, and refusing a replay after re-pairing.
web-session-tabs-sync.test.tsstill passes.pnpm tc:webandpnpm run check:code-quality:changedpass.I manually tested these changes locally
Automated tests added/updated, or explained why not below
Agent skill upstream boundary
Notes
SSH/remote: this is the paired-host case. Losing contact is treated as "not delivered yet", never as "closed". Mobile: there's no change to the mobile app. The paired web client uses this same path and gets the fix.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)